package com.collection.treesets;

import java.util.TreeSet;

public class CopyElementsOfTreeSetToArrayExample {
	public static void main(String[] args) {
		 
	    //create object of TreeSet
	    TreeSet tSet = new TreeSet();
	   
	    //add elements to TreeSet object
	    tSet.add(new Integer("1"));
	    tSet.add(new Integer("2"));
	    tSet.add(new Integer("3"));
	   
	    /*
	      To copy all elements of java TreeSet object into array use
	      Object[] toArray() method.
	    */
	   
	    Object[] objArray = tSet.toArray();
	   
	    //display contents of Object array
	    System.out.println("TreeSet elements are copied into an Array. Now Array Contains..");
	    for(int index=0; index < objArray.length ; index++)
	      System.out.println(objArray[index]);
	  }
}
